// page/detail/pages/feedback/feedback.js
const utils = require('../../../utils/util.js');
let myRequest = require('../../../common/script/myRequest.js');
let api = require('../../../common/script/api.js');
let login = require('../../../common/script/login');
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    dataList: [],
    orgcode: '',
    isEnd: false,
    noData: true
  },
  toFeedBasckDetail(e) {
    const that = this;
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/package/pages/feedBasckDetail/feedBasckDetail?id=${id}&orgcode=${that.data.orgcode}`,
    })
  },
  getData() {
    let that = this;
    let data = {
      page: that.data.page,
      limit: 20,
    }
    wx.showLoading({
      title: '加载中...',
    })
    myRequest.EasyHttp.post(api.reqUrls.feedbackList, data).then(res => {
      wx.hideLoading();
      if (res.data.status == 1) {
        that.setData({
          dataList: res.data.result,
        })
      } else {
        wx.showModal({
          content: res.data.msg,
          showCancel: false,
          confirmText: '我知道了',
          confirmColor: '#ff5151',
          success(e) {}
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this;
    if (options.scene) {
      let sceneObj = utils.parseQueryString(options.scene)
      that.setData({
        orgcode: sceneObj.orgcode
      })
    } else {
      let scene = decodeURIComponent(options.q)
      const url = scene.substring(scene.indexOf('?') + 1)
      const params = url.split('&')
        .reduce(function (acc, param) {
          const [key, value] = param.split('=');
          acc[key] = decodeURIComponent(value);
          return acc;
        }, {});
      console.log(params, 123)
      let orgcode = params['orgcode'];
      that.setData({
        orgcode: orgcode
      })
    }
    login.checkLogin().then(res => {
      that.getData()
    }).catch(err => {
      app.appCallBack = (e) => {
        that.getData()
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage() {

  // }
})